// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
  if (event.action == "add") {
    return await db.collection('comment')
    .add({
      data: {
        context: event.obj.context,
        id: event.obj.id,
        imgUrl: event.obj.imgUrl,
        time: event.obj.time,
        name: event.obj.name,
        videoId: event.obj.videoId
      }
    })
  }
  if (event.action == "delete") {
    return await db.collection('comment')
    .doc(event.id)
    .remove()
  }
}